<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>props</title>
  </head>
  <body>
    <div id="test1"></div>

    <script
      src="https://unpkg.com/react@16/umd/react.production.min.js"
      crossorigin
    ></script>
    <script
      src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"
      crossorigin
    ></script>
    <script src="https://unpkg.com/prop-types@15.6/prop-types.min.js"></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>

    <script type="text/babel">
      function Person(props) {
        const { name, age, sex } = props;
        return (
          <ul>
            <li>姓名:{name}</li>
            <li>性别:{sex}</li>
            <li>年龄:{age}</li>
          </ul>
        );
      }

      //对标签属性进行类型/必要性的限制
      Person.propTypes = {
        name: PropTypes.string.isRequired, //限制name 必传,且为字符串
        sex: PropTypes.string, //限制 sex 为字符串
        age: PropTypes.number, //限制 age 为数字
      };
      //对props 进行参数默认
      Person.defaultProps = {
        sex: "默认参数", //sex 默认参数
        age: 10, //默认参数
      };
      let prop = {
        name: "咱上哪",
      };
      ReactDOM.render(<Person {...prop} />, document.getElementById("test1"));
    </script>
  </body>
</html>
